﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nexterday.Linq.Autocompiler
{
    public static class TypeExtensions
    {
        public static IEnumerable<Type> GetGenericIEnumerables(this Type type)
        {
            if (type.IsGenericType == true
                        && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
            {
                yield return type.GetGenericArguments()[0];
            }
            foreach( var i in
            type.GetInterfaces()
                    .Where(t => t.IsGenericType == true
                        && t.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                    .Select(t => t.GetGenericArguments()[0]))
                    {
                yield return i;
            }
        }

    }
}
